package vip.huhaiong.hlfood.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.huhaiong.hlfood.mapper.UserMapper;
import vip.huhaiong.hlfood.pojo.Rs;
import vip.huhaiong.hlfood.pojo.UserInfo;
import vip.huhaiong.hlfood.service.UserService;
import vip.huhaiong.hlfood.utils.GetOpenId;
import vip.huhaiong.hlfood.utils.RsUtil;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    GetOpenId getOpenId;
    UserMapper userMapper;
    @Autowired
    public UserServiceImpl(UserMapper userMapper, GetOpenId getOpenId){
        this.userMapper = userMapper;
        this.getOpenId = getOpenId;
    }
    @Override
    public Rs getListByOpenId(String openid) {
        List<UserInfo> list = userMapper.selectShouCang(openid);
        return RsUtil.success("获取成功",list);
    }

    @Override
    public Rs remove(Integer id) {
        userMapper.delete(id);
        return RsUtil.success("删除成功");
    }

    @Override
    public Rs add(UserInfo pojo) {
        userMapper.insert(pojo);
        return RsUtil.success("添加成功");
    }

    @Override
    public Rs getOpenId(String code) {
        JSONObject openId = getOpenId.getOpenId(code);
        return RsUtil.success("获取成功",openId);
    }
}
